package com.dsbj.icardservice.controller;

import com.dsbj.common.msg.ResponseMessage;
import com.dsbj.icardservice.entity.District;
import com.dsbj.icardservice.entity.Employee;
import com.dsbj.icardservice.service.DistrictService;
import com.dsbj.icardservice.service.EmployeeService;
import com.dsbj.icardservice.utils.strprocess.ObjectParse;
import com.dsbj.icardservice.utils.strprocess.StrUtil;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author cjw 2019-09-24
 */
@RestController
@RequestMapping(value = "/district")
public class DistrictController extends BaseController {

	@Resource
	private DistrictService districtService;

	/**
	 * 根据districtno模糊查询district信息。
	 * @param
	 * @return
	 * @author cjw 2019-09-23
	 */
	@RequestMapping(value = "/getDistrictByNoDim",method = RequestMethod.POST)
	public ResponseMessage getDistrictByNoDim(@RequestBody Map<String,Object> map){

		//解析传来的参数
		String districtno=null;
		try{
			districtno= ObjectParse.parse_toStr_elseException(map.get("districtno"));
		}catch (Exception e){
			return ResponseMessage.error("传入的参数有误!");
		}

		/**
		 * 根据districtno模糊查询district信息。
		 */
		List<District> districts=districtService.getDistrictByNoDim(districtno);
		return ResponseMessage.ok(districts);
	}

	/**
	 * 根据districtname模糊查询district信息。
	 * tip1: districtname中亦可传入districtno。
	 * @param
	 * @return
	 * @author cjw 2019-09-23
	 */
	@RequestMapping(value = "/getDistrictByNameDim",method = RequestMethod.POST)
	public ResponseMessage getDistrictByNameDim(@RequestBody Map<String,Object> map){

		//解析传来的参数
		String districtName=null;
		try{
			districtName= ObjectParse.parse_toStr_elseException(map.get("districtname"));
		}catch (Exception e){
			return ResponseMessage.error("传入的参数有误!");
		}

		/**
		 * 根据districtname模糊查询district信息。
		 */
		List<District> districts=districtService.getDistrictByNameDim(districtName);
		return ResponseMessage.ok(districts);
	}

	/**
	 * 获取district列表。
	 * @param
	 * @return
	 * @author cjw 2019-09-26
	 */
	@RequestMapping(value = "/getDistricts",method = RequestMethod.POST)
	public ResponseMessage getDistricts(@RequestBody Map<String,Object> map){
		//StrUtil.prettyPrint("map",map);
		String companyno=ObjectParse.parse_toStr(map.get("companyno"));
		if(StrUtil.isEmpty(companyno)){
			return ResponseMessage.error("参数错误,缺少companyno");
		}
		/**
		 * 获取district列表。
		 */
		List<District> districts=districtService.getDistricts(companyno);
		return ResponseMessage.ok(districts);
	}






}
